<template>
     <el-card>
        <el-form :inline="true"  class="demo-form-inline">
            <el-form-item label="一级分类">
                <el-select :disabled="scene==0?false:true" v-model="categoryStore.c1Id" @change="handler">
                    <el-option v-for="(c1,index) in categoryStore.c1Arr" :key="c1.id" :label="c1.name" :value="c1.id"></el-option>
                </el-select>
            </el-form-item>
            <el-form-item  label="二级分类">
                <el-select :disabled="scene==0?false:true" v-model="categoryStore.c2Id" @change="handler1">
                    <el-option v-for="(c2,index) in categoryStore.c2Arr" :key="c2.id" :label="c2.name" :value="c2.id"></el-option>
                </el-select>
            </el-form-item>
            <el-form-item label="三级分类">
                <el-select :disabled="scene==0?false:true" v-model="categoryStore.c3Id">
                    <el-option v-for="(c3,index) in categoryStore.c3Arr" :key="c3.id" :label="c3.name" :value="c3.id"></el-option>
                </el-select>
            </el-form-item>
        </el-form>
    </el-card>
</template>
<script setup lang="ts">

import { onMounted,ref } from 'vue';
//引入分类相关的仓库
import useCategoryStore from '@/store/modules/category';
//接收父组件传递
defineProps(['scene'])

let categoryStore=useCategoryStore();

//存储一级分类数据



onMounted(()=>{
    //获取一级分类的数据
    getC1();
})


const getC1=async ()=>{
    categoryStore.getC1();

}

//一级分类下拉菜单change事件,获取二级分类数据
const handler=()=>{
    //需要将二级和三级分类数据清空
    categoryStore.c2Id=''
    categoryStore.c3Id=''
    categoryStore.c2Arr=[]
    categoryStore.c3Arr=[]
    //通知仓库获取二级分类的数据
    categoryStore.getC2();
}


//获取三级分类
const handler1=()=>{
    categoryStore.c3Id=''
    categoryStore.c3Arr=[]
    categoryStore.getC3();
}









</script>
<style scoped>
.demo-form-inline .el-input {
  --el-input-width: 220px;
}

.demo-form-inline .el-select {
  --el-select-width: 220px;
}
</style>